<?php
class Custom_View_Helper_Addjavascript extends Zend_View_Helper_Abstract
{
    public function addJavascript($file, $position = '')
    {
        $positions   = array('first', '', 'last');
        if (!in_array($position, $positions, true)) {
            throw new Custom_View_Exception(sprintf(
                'The position "%s" does not exist (available positions: %s).',
                $position, implode(', ', $positions)
            ));
        }

        $js =  $this->view->baseUrl() . $this->view->pathJs . $file;

        switch ($position){
            case 'first':
                $this->view->headScript()->prependFile($js);
                break;
            case '':
                $this->view->headScript()->appendFile($js);
                break;
            case 'last':
                $this->view->headScript()->offsetSetFile(100, $js);
                break;
        }
    }
}